//
//  FocusThreeAlbumCell.m
//  Everest
//
//  Created by Liu Chengbo on 14/12/27.
//  Copyright (c) 2014年 ThreeL. All rights reserved.
//

#import "FocusThreeAlbumCell.h"
#import "UIImageView+WebCache.h"
#import "UIColor+AddColor.h"

#import "TwoType.h"
@interface FocusThreeAlbumCell ()
@property (nonatomic, retain) UIImageView *bigImageView;
@property (nonatomic, retain) UILabel *albumeLabel;
@property (nonatomic, retain) UILabel *titleLabel;
@property (nonatomic, retain) UIImageView *playImageView;
@property (nonatomic, retain) UILabel *playLabel;
@property (nonatomic, retain) UILabel *timeLabel;
@end

@implementation FocusThreeAlbumCell
- (void)dealloc
{
    [_twoTy release];
    [_bigImageView release];
    [_albumeLabel release];
    [_titleLabel release];
    [_playImageView release];
    [_playLabel release];
    [_timeLabel release];
    [super dealloc];
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.bigImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.bigImageView];
//        self.bigImageView.backgroundColor = [UIColor grayColor];
        
        self.albumeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.albumeLabel];
        
        self.titleLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.titleLabel];
//        self.titleLabel.backgroundColor = [UIColor redColor];
        
        self.playImageView = [[UIImageView alloc] init];
        [self.contentView addSubview:self.playImageView];
//        self.playImageView.backgroundColor = [UIColor blueColor];
        
        self.playLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.playLabel];
//        self.playLabel.backgroundColor = [UIColor purpleColor];
        
        self.timeLabel = [[UILabel alloc] init];
        [self.contentView addSubview:self.timeLabel];
//        self.timeLabel.backgroundColor = [UIColor greenColor];
    }
    return self;
}

- (void)setTwoTy:(TwoType *)twoTy
{
    if (_twoTy != twoTy) {
        [_twoTy release];
        _twoTy = [twoTy retain];
    }
    // 给 照片 赋值
    [self.bigImageView setImageWithURL:[NSURL URLWithString:self.twoTy.albumCoverUrl290]];
    // 给 标题 赋值
    self.titleLabel.text = self.twoTy.title;
    // 给 播放次数 赋值
    self.playLabel.text = [self.twoTy.playsCounts description];
    // 给 创建时间 赋值
    NSString *tempstr = [self.twoTy.lastUptrackAt description];
    NSString *istr = [tempstr substringToIndex:10];
    int uptime = [istr intValue];
    NSDate *date = [NSDate date];
    NSTimeInterval time = [date timeIntervalSince1970];
    NSDate *date1 = [NSDate dateWithTimeIntervalSinceNow:- (time - uptime)];
    NSString *day = [NSString stringWithFormat:@"%@", date1];
    NSString *day1 = [day substringToIndex:10];
    self.timeLabel.text = [NSString stringWithFormat:@"创建时间   %@", day1];
    // 给 播放次数 赋值
    // 转为int
    int times = [self.twoTy.playsCounts intValue];
    // 转为NSString
    NSString *timeStr = [NSString stringWithFormat:@"%@", self.twoTy.playsCounts];
    if ([timeStr length] > 4) {
        
        self.playLabel.text = [NSString stringWithFormat:@"%d万", times / 10000];
        
    } else {
        
        self.playLabel.text = [self.twoTy.playsCounts description];
    }
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.bigImageView.frame = CGRectMake(0, 0, 100, 100);
    
    self.albumeLabel.frame = CGRectMake(110, 10, 20, 20);
    self.albumeLabel.text = @"辑";
    self.albumeLabel.textColor = [UIColor kuGouColor];
    self.albumeLabel.font = [UIFont systemFontOfSize:16];
    
    self.titleLabel.frame = CGRectMake(140, 10, self.contentView.bounds.size.width - 140 - 10, 40);
    self.titleLabel.numberOfLines = 0;
    self.titleLabel.font = [UIFont systemFontOfSize:16];
    
    self.playImageView.frame = CGRectMake(110, 60, 15, 15);
    self.playImageView.image = [UIImage imageNamed:@"iconfont-play.png"];
    
    self.playLabel.frame = CGRectMake(125, 60, 60, 15);
    self.playLabel.font = [UIFont systemFontOfSize:12];
    self.playLabel.textColor = [UIColor grayColor];
    
    self.timeLabel.frame = CGRectMake(110, 80, 180, 15);
    self.timeLabel.font = [UIFont systemFontOfSize:10];
    self.timeLabel.textColor = [UIColor grayColor];
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
